﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Traxz.Models;

namespace Traxz.Controllers
{ 
    public class AdminController : Controller
    {
        private TraxzDBEntities db = new TraxzDBEntities();

        //
        // GET: /Admin/

        public ViewResult Index()
        {
            return View("AdminControlPanel",db.aspnet_Users.ToList());
        }

        //
        // GET: /Admin/Details/5

        public ViewResult Details(Guid id)
        {
            aspnet_Users aspnet_users = db.aspnet_Users.Find(id);
            return View(aspnet_users);
        }

        //
        // GET: /Admin/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Admin/Create

        [HttpPost]
        public ActionResult Create(aspnet_Users aspnet_users)
        {
            if (ModelState.IsValid)
            {
                aspnet_users.UserId = Guid.NewGuid();
                db.aspnet_Users.Add(aspnet_users);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(aspnet_users);
        }
        
        //
        // GET: /Admin/Edit/5
 
        public ActionResult Edit(Guid id)
        {
            aspnet_Users aspnet_users = db.aspnet_Users.Find(id);
            return View(aspnet_users);
        }

        //
        // POST: /Admin/Edit/5

        [HttpPost]
        public ActionResult Edit(aspnet_Users aspnet_users)
        {
            if (ModelState.IsValid)
            {
                db.Entry(aspnet_users).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(aspnet_users);
        }

        //
        // GET: /Admin/Delete/5
 
        public ActionResult Delete(Guid id)
        {
            aspnet_Users aspnet_users = db.aspnet_Users.Find(id);
            return View(aspnet_users);
        }

        //
        // POST: /Admin/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {            
            aspnet_Users aspnet_users = db.aspnet_Users.Find(id);
            db.aspnet_Users.Remove(aspnet_users);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}